﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Silvermoon.Controls
{
    /// <summary>
    /// Abstract control for scroll bars.
    /// </summary>
    public abstract class ScrollBar : NotifyEventControl, IScrollEventBehavior
    {
        #region Fields

        protected int position;
        protected int minimum;
        protected int maximum = 100;
        protected int largeChange = 1;
        private bool showBackground = true;

        #endregion
        #region ctor/dtor


        #endregion
        #region Properties

        public int Value
        {
            get { return position; }
            set { if (position != value) { position = value; OnValueChanged(); Invalidate(InvalidationFlag.Appearance | InvalidationFlag.Layout); } }
        }

        public int Minimum
        {
            get { return minimum; }
            set { if (value < 0) value = 0; if (minimum != value) { minimum = value; Invalidate(InvalidationFlag.Appearance | InvalidationFlag.Layout); } }
        }

        public int Maximum
        {
            get { return maximum; }
            set { if (value < 0) value = 0; if (maximum != value) { maximum = value; Invalidate(InvalidationFlag.Appearance | InvalidationFlag.Layout); } }
        }

        public int LargeChange
        {
            get { return largeChange; }
            set { if (largeChange != value) { largeChange = value; Invalidate(InvalidationFlag.Appearance|InvalidationFlag.Layout); } }
        }

        public bool ShowBackground
        {
            get { return showBackground; }
            set
            {
                if (showBackground != value)
                {
                    showBackground = value;
                    Invalidate(InvalidationFlag.Appearance);
                }
            }
        }

        #endregion
        #region Methods

        protected virtual void OnValueChanged()
        {
            if (ValueChanged != null) ValueChanged(this, EventArgs.Empty);
        }
        #endregion

        public event EventHandler ValueChanged;


        #region IScrollEventBehavior Members

        public void OnScroll(ScrollEventArgs e)
        {
            e.Handled = true;
            e.Cancel = true;
        }

        public void OnBeginScrollData(BeginScrollEventArgs e)
        {
            e.Handled = true;
            e.Cancel = true;
        }

        public void OnEndScrollData(EndScrollEventArgs e)
        {
            e.Handled = true;
        }

        #endregion
    }
}
